<?php namespace Member\Controller;

use Hdphp\Controller\Controller;
use Member\Model\User;


class LoginController extends Controller
{
	protected $db;

	public function __init()
	{
		$this->db=new User;
	}

	public function reg()
	{
		if(IS_POST)
		{
			if($this->db->reg())
			{
				$this->success('注册成功','Member/Login/login');	
			}
			else
			{
				$this->error($this->db->getError());
			}
		}
		else
		{
			View::make('Template/register.html');
		}
	}

	public function log()
	{
		if(IS_POST)
		{
			if($this->db->log())
			{
				// $this->success('登录成功',"Home/Index/index");
				go('Home/Index/index');
			}
			else
			{
				$this->error($this->db->getError());
			}
		}
		else
		{
			View::make('Template/login.html');
		}
	}

	public function quit()
	{
		session_unset();
		session_destroy();
		go('log');
	}

	public function code()
	{
		Code::make();
	}
}